local skynet = require "skynet"
local cluster = require "skynet.cluster"
require "skynet.manager"

local filelog = require "filelog"
local configdao = require "configdao"

skynet.start(function()
	skynet.error("robotnode start")
	skynet.newservice("nodelog")
	local confsharesvr = skynet.newservice("confshare")
	skynet.call(confsharesvr, "lua", "start")

    local pbcservice = skynet.uniqueservice("pbcservice")
	skynet.call(pbcservice, "lua", "initproto", "../proto/primary.proto")
	skynet.call(pbcservice, "lua", "initproto", "../psznode/psz.proto")
	skynet.call(pbcservice, "lua", "initproto", "../dnnode/dn.proto")
	skynet.call(pbcservice, "lua", "initproto", "../pdknode/pdk.proto")
	skynet.call(pbcservice, "lua", "initproto", "../ddznode/ddz.proto")

	local robotnode = configdao.get_cfgsvrs_key("robotnode")
	if robotnode and robotnode.debug_console_port then
		skynet.newservice("debug_console",robotnode.debug_console_port)
	end

    --连接到redis
	skynet.name(".gmmqredis", skynet.newservice("redisdb"))	
	skynet.call(".gmmqredis", "lua", "init", configdao.get_cfgsvrs_key("gmmqredis"))

    skynet.name(".nodeuuid", skynet.uniqueservice("nodeuuid") )
    skynet.name(".schedulemgr", skynet.uniqueservice("schedulemgr") )
    skynet.name(".inventorymgr", skynet.uniqueservice("inventorymgr") )
    skynet.name(".coinlog", skynet.newservice("datalog"))           -- 金币数据日志
	skynet.call(".coinlog", "lua", "init", "coin")         
	skynet.name(".diamondlog", skynet.newservice("datalog"))        -- 金豆数据日志
	skynet.call(".diamondlog", "lua", "init", "diamond")
	skynet.name(".router", skynet.uniqueservice("router") )
    skynet.name(".mainnode", skynet.uniqueservice("robotnode") )
    skynet.name(".robotmgr", skynet.uniqueservice("robotmgr") )
    skynet.call(".robotmgr", "lua", "init", {
		maxrobot = robotnode.maxrobot or 10000,
		agentsize = robotnode.agentsize or 20,
		agentincr = robotnode.agentincr or 20,
	})
    cluster.open("robotnode")

    --默认关闭机器人
    skynet.send(".schedulemgr", "lua", "change_robot_state", false)

	skynet.exit()
end)
